//
//  CCBaseViewController.m
//  Activity
//
//  Created by its on 15/5/7.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCBaseViewController.h"
#import "CCDevice.h"
#import <ReactiveCocoa/ReactiveCocoa.h>

@interface CCBaseViewController ()
@property (nonatomic, strong) UIView *statusBar;
@property (nonatomic, strong) UINavigationBar *naviBar;

@end

@implementation CCBaseViewController

- (void)viewDidLoad {
//    self.edgesForExtendedLayout = UIRectEdgeNone;
  [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
}

- (void)loadView {
  UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  view.backgroundColor = [UIColor whiteColor];
  self.view = view;
}

- (void) showErrorView:(NSString *) msg block:(void(^)())block {
  UILabel *label = [UILabel new];
  label.textAlignment = NSTextAlignmentCenter;
  label.numberOfLines = 0;
  label.textColor = [UIColor lightGrayColor];
  label.text = msg;
  label.tag = 10001;
  [self.view addSubview: label];
  [label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(self.view);
    make.left.equalTo(self.view).offset(40);
    make.right.equalTo(self.view).offset(-40);
  }];
  
  UIButton *refresh = [UIButton buttonWithType:UIButtonTypeCustom];
  refresh.tag = 10002;
  refresh.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
    block();
    return [RACSignal empty];
  }];
  [refresh setTitle:@"重新加载" forState:UIControlStateNormal];
  [refresh setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  refresh.layer.cornerRadius = 1.0f;
  refresh.layer.borderColor = [UIColor lightGrayColor].CGColor;
  refresh.layer.borderWidth = 1.0f;
  [self.view addSubview:refresh];
  [refresh mas_makeConstraints:^(MASConstraintMaker *make) {
    make.size.mas_equalTo(CGSizeMake(100, 40));
    make.centerX.equalTo(self.view);
    make.top.equalTo([self.view viewWithTag:10001].mas_bottom).offset(10);
  }];
}

- (void) hiddenErrorView {
  [[self.view viewWithTag:10001] removeFromSuperview];
  [[self.view viewWithTag:10002] removeFromSuperview];
}
@end
